require 'watir'
require 'test\unit\assertions'
include Test::Unit::Assertions

class Watirr
  def initialize(ie_title=nil)
    if ie_title
      @watir = Watir::IE.attach(:title, /#{ie_title}/)
    else
      @watir = Watir::IE.new
    end
  end

  def close
    @watir.close
  end

  def open_url(null, url)
    @watir.goto url
  end

  def type(target, value)
    begin
      @watir.text_field(:id, target).set(value)
    rescue
      @watir.text_field(:name, target).set(value)
    end
  end

  def click_button(target, null)
    begin
      @watir.button(:id, target).click
    rescue
      @watir.button(:name, target).click
    end
  end

  def click_link(target, null)
    @watir.link(:url, target).click
  end

  def assert_text(target, value)
    begin
      assert_equal value, @watir.text_field(:id, target).value
    rescue
      assert_equal value, @watir.text_field(:name, target).value
    end
  end

end

